﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBA.Data;
using DBA.Data.ADO;
using DBA.Bll;
using DBA.Web.UI;

namespace DBA.Web.PublicControl
{
    public partial class SelectTeachers : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            ddlBind();
            Bind(1, null);
        }

        protected void ddlBind()
        {
            BaseCodeDDL.DdlInit(ddlXi, "Xi");//绑定系
            BaseCodeDDL.DdlInit(ddlSuo, "Suo");
            BaseCodeDDL.DdlInit(ddlDept, "sys_department");
            BaseCodeDDL.DdlInit(ddlJszwzg, "JSZWZG");

        }

        protected void linkBtnSearch_Click(object sender, EventArgs e)
        {
            IDictionary<String, String> dict = new Dictionary<String, String>();
            dict.Add("Name", txtName.Text.Trim());
            dict.Add("SalaryID", txtSalaryID.Text.Trim());
            dict.Add("Xi_ID", ddlXi.SelectedValue);
            dict.Add("Suo_ID", ddlSuo.SelectedValue);
            dict.Add("Dpt_ID", ddlDept.SelectedValue);
            dict.Add("jszwzgID", ddlJszwzg.SelectedValue);
            ViewState["conditions"] = dict;
            Bind(1, dict);
        }

        private void Bind(int pageIdx, IDictionary<String, String> dict)
        {

            string sql = "select a.*,b.Name as XiName,c.Name as SuoName,d.Name as DptName,f.name as PartName,g.Name as JsName from  ";
            sql += "EmployeeInfo a left join Xi b on a.Xi_ID=b.Xi_ID  left join Suo c on a.Suo_ID=c.Suo_ID ";
            sql += "left join sys_department d on a.dpt_id=d.dpt_id  left join PartyDuty f on a.PD_id=f.PD_id ";
            sql += "left join JSZWZG g on a.jszwzgID=g.jszwzgID left join EduAttainments h on a.EaID=h.EaID ";
            sql += " where 1=1 ";
            DataAccessLibrary dal = CommonQuery.DataAccessLibrary;
            dal.ManagerParameter.ClearParameter();
            if (dict != null)
            {
                if (dict["Name"] != null)
                {
                    sql += " and a.Name like '%'+@Name+'%'";
                    dal.ManagerParameter.AddNewInParameter("Name", dict["Name"].ToString());
                }
                if (!dict["SalaryID"].ToString().Equals(string.Empty))
                {
                    sql += " and a.SalaryID =@SalaryID";
                    dal.ManagerParameter.AddNewInParameter("SalaryID", dict["SalaryID"].ToString());
                }

                if (!dict["Xi_ID"].ToString().Equals("-1"))
                {
                    sql += " and a.Xi_ID =@Xi_ID";
                    dal.ManagerParameter.AddNewInParameter("Xi_ID", dict["Xi_ID"].ToString());
                }

                if (!dict["Suo_ID"].ToString().Equals("-1"))
                {
                    sql += " and a.Suo_ID =@Suo_ID";
                    dal.ManagerParameter.AddNewInParameter("Suo_ID", dict["Suo_ID"].ToString());
                }

                if (!dict["Dpt_ID"].ToString().Equals("-1"))
                {
                    sql += " and a.Dpt_ID =@Dpt_ID";
                    dal.ManagerParameter.AddNewInParameter("Dpt_ID", dict["Dpt_ID"].ToString());
                }

                if (!dict["jszwzgID"].ToString().Equals("-1"))
                {
                    sql += " and a.jszwzgID =@jszwzgID";
                    dal.ManagerParameter.AddNewInParameter("jszwzgID", dict["jszwzgID"].ToString());
                }
            }


            int iCount = 0;

            replData.DataSource = dal.ModifyData.GetPageDataTable("(" + sql + ")", "*", "", "EmployeeID DESC", pageIdx, 10, ManagerSQL.PageViewTableType.MixtureTable, ref iCount);
            replData.DataBind();
            AspNetPager1.RecordCount = iCount;

        }

        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            IDictionary<String, String> dict = null;
            if (ViewState["conditions"] != null)
            {
                dict = (IDictionary<String, String>)ViewState["conditions"];
            }
            Bind(e.NewPageIndex, dict);
        }

    }
}